package scjp.preparation.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
import java.util.Properties;

import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.RowSetProvider;

public class DbUpdate1 {

	public static void main(String[] args) throws SQLException {
		Properties props = new Properties();
		props.put("user", "root");
		props.put("password", "admin");

		String sql = "update contact set phoneNo=? where id = 1";

		try (Connection connection = DriverManager.getConnection(
				"jdbc:mysql://localhost:3306/addressbook", props)) {
			CachedRowSet crs = RowSetProvider.newFactory().createCachedRowSet();
			crs.setCommand("SELECT * FROM contact WHERE firstName = \"Michael\"");
			connection.setAutoCommit(false);
			int[] keys = {1};
			crs.setKeyColumns(keys);
			crs.execute(connection);
			crs.next();
			crs.updateRow();
			crs.acceptChanges();
			
		} catch (SQLException e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}
}
